/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer.jxmap.map;

import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.mapviewer.TileFactory;
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;

/**
 *
 * @author Timon Veenstra
 */
public class JXMapPanel extends JXMapViewer{

    private final ExplorerManager manager;

    public JXMapPanel(ExplorerManager manager) {
        this.manager = manager;
        //setDefaultProvider(DefaultProviders.OpenStreetMaps);

        setOpaque(true);
        final int max = 19;
        TileFactoryInfo info = new TileFactoryInfo(1, max - 8, max,
                256, true, true, // tile size is 256 and x/y orientation is normal
                "http://tile.openstreetmap.org",//5/15/10.png",
                "x", "y", "z") {

            @Override
            public String getTileUrl(int x, int y, int zoom) {
                int calculatedZoom = max - zoom;
                return this.baseURL + "/" + calculatedZoom + "/" + x + "/" + y + ".png";
            }
        };
        TileFactory tf = new DefaultTileFactory(info);
        setTileFactory(tf);

        //painter = new SensorDataOverlayPainter(jXMapKit1.getMainMap());

        //jXMapKit1.getMainMap().setOverlayPainter(painter);
        //jXMapKit1.setAddressLocation(new GeoPosition(51.5, 0));
        setAddressLocation(new GeoPosition(51.5310707, 3.8955812));
//        setAddressLocationShown(false);
//        setZoomButtonsVisible(false);
//        setZoomSliderVisible(false);
//        setMiniMapVisible(false);
        setZoom(6);
        putClientProperty("print.printable", true);
    }

    @Override
     public void addNotify() {
        super.addNotify();
        ExplorerUtils.activateActions(manager, true);
    }

    @Override
    public void removeNotify() {
        ExplorerUtils.activateActions(manager, false);
        super.removeNotify();
    }


}
